package main

import (
	log "github.com/Sirupsen/logrus"
	"github.com/urfave/cli"
	"os"
)

const usage = `mydocker is a simple container runtime implementation.
			   The purpose of this project is to learn how docker works and how to write a docker by ourselves
			   Enjoy it, just for fun.`

func main() {
	app := cli.NewApp()
	app.Name = "JoDocker"
	app.Usage = usage
	app.Commands = []cli.Command{
		initCommand,
		runCommand,
		commitCommand,
		listCommand,
		logCommand,
		execCommand,
		stopCommand,
		removeCommand,
		networkCommand,
	}
	app.Before = func(context *cli.Context) error {
		log.SetFormatter(&log.JSONFormatter{})
		log.SetOutput(os.Stdout)
		return nil
	}
	if err := app.Run(os.Args); err != nil {
		log.Fatal(err)
	}
}

//func main1() {
//	fmt.Printf("Hello, world.\n")
//	cmd := exec.Command("sh")
//	//cmd.Env = []string{"PS1=-[namespace-process]-#"}
//	cmd.SysProcAttr = &syscall.SysProcAttr{
//		// CLONE_NEWNS -- Mount Namespace
//		Cloneflags: syscall.CLONE_NEWNS | syscall.CLONE_NEWUTS | syscall.CLONE_NEWIPC | syscall.CLONE_NEWPID | syscall.CLONE_NEWUSER,
//		UidMappings: []syscall.SysProcIDMap{
//			{
//				ContainerID: 0,
//				HostID:      os.Getuid(),
//				Size:        1,
//			},
//		},
//		GidMappings: []syscall.SysProcIDMap{
//			{
//				ContainerID: 0,
//				HostID:      os.Getgid(),
//				Size:        1,
//			},
//		},
//	}
//	cmd.Stdin = os.Stdin
//	cmd.Stdout = os.Stdout
//	cmd.Stderr = os.Stderr
//	if err := cmd.Run(); err != nil {
//		log.Fatal(err)
//	}
//}
